package com.boot.thymeleaf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;

@Controller
public class TestController {

    @GetMapping("/index")
    public String goIndex(HttpSession session, Model model, HttpServletResponse rp) {


        Cookie cookie = new Cookie("auth11MyCookie", "sdfsdfsfsdf");
        cookie.setDomain("gmall.com");
        cookie.setPath("/");
        rp.addCookie(cookie);

        session.setAttribute("name", "我是一");

        List<String> tagets = Arrays.asList("钱", "技能", "女人");
        session.setAttribute("tagets", tagets);

        return "index";
    }

    @GetMapping("/accept/rd")
    public String goIndex222(HttpSession session, Model model, HttpServletRequest rq) {
        System.out.println(rq.getHeader("token"));
        session.setAttribute("name", rq.getParameter("name"));

        session.setAttribute("tagets", rq.getParameter("tagets"));

        return "index";
    }
}
